/* ATMFactoryImpl.java
 *
 * Author:	Malcolm Staudacher
 * Date:	Nov 1, 2008
 *
 */

package fhv.itb.ec.atm;

import java.util.Vector;
import org.omg.CORBA.ORB;
import org.omg.CORBA.ORBPackage.InvalidName;
import org.omg.CosNaming.NameComponent;
import org.omg.CosNaming.NamingContextExt;
import org.omg.CosNaming.NamingContextExtHelper;
import org.omg.PortableServer.POA;
import org.omg.PortableServer.POAHelper;


public class ATMFactoryImpl extends ATMFactoryPOA {

	private ORB m_orb;
	
	
	public ATMFactoryImpl() {

	}
	
	
	public ATM createATM() {
		POA rootPOA;
		ATM aRef = null;
		
		if (m_orb != null) {
			
			try {
				rootPOA = POAHelper.narrow(m_orb.resolve_initial_references("RootPOA"));
				rootPOA.the_POAManager().activate();
				ATMImpl atmi = new ATMImpl();
				org.omg.CORBA.Object ref = rootPOA.servant_to_reference(atmi);
				aRef = ATMHelper.narrow(ref);
				System.out.println("ATMFactory ready...");
			} catch (Exception e) {
				System.out.println("Error while creating ATMImpl instances");
				e.printStackTrace();
			}
			
		} else {
			System.out.println("No ORB in ATMFactoryImpl");
		}
		
		return aRef;
	}

	
	public void setOrb(ORB orb) {
		this.m_orb = orb;
	}
	

}
